package com.trkj.controllers;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.trkj.pojos.BigOffice;
import com.trkj.pojos.ChargeprojectTable;
import com.trkj.pojos.SmallOffice;
import com.trkj.service.Hosp_patien_service;
import com.trkj.vo.BigOfficeVo;
import com.trkj.vo.Doctor_arrangeVo;
import com.trkj.vo.Serach_condition;

/**
 * 门诊管理控制器
 * 1.门诊挂号
 * 2.办诊疗卡
 * 3.诊疗卡管理
 * 4.挂号管理
 * 5.查看详情
 * @author 小志
 *
 */
@Controller
public class Hosp_patient_controller {
	
	@Autowired
	Hosp_patien_service hosp_patien;
	/**
	 * 1.加载科室
	 * @return
	 */
	@RequestMapping("to_hosp_patient_registration")
	public ModelAndView to_hosp_patient_guahao(ModelAndView mv){
		mv.addObject("office", hosp_patien.getOffice());
		mv.setViewName("hosp_patient_registration");
		return mv;
	}
	/**
	 * 2.办诊疗卡
	 * @return
	 */
	@RequestMapping("to_hosp_apply_card")
	public String to_hosp_apply_card(){
		return "hosp_apply_card";
	}
	
	/**
	 * 3.诊疗卡管理
	 * @return
	 */
	@RequestMapping("to_hosp_card_manage")
	public 	String to_hosp_card_manage(){
		return "hosp_card_manage";
	}
	
	/**
	 * 4.挂号管理
	 * @return
	 */
	@RequestMapping("to_hosp_registration_manage")
	public String to_hosp_registration_manage(){
		return "hosp_registration_manage";
	}
	
	/**
	 * 5.查看详情
	 * 
	 */
	@RequestMapping("to_hosp_registration_detail")
	public String to_hosp_registration_detail(){
		return "hosp_registration_detail";
	}
	
	/**
	 * 多条件分页查询门诊挂号
	 * @param patient
	 * @return
	 */
	@RequestMapping("load_menzhen")
	@ResponseBody
	public Map<String,Object> load_menzhen(Serach_condition patient){
		System.out.println(patient);
		return hosp_patien.load_menzhen(patient);
	}
	
	/**
	 * 跳转到医生选择列表
	 * @return
	 * @throws ParseException 
	 */
	@RequestMapping("to_doctor_select")
	public ModelAndView to_doctor_select(Serach_condition condition) throws ParseException{
		System.out.println(condition.getSmall_office_id()+"======"+condition.getDate()+"======="+condition.getClasses());
		ModelAndView mv=new ModelAndView();
		mv.setViewName("doctor_select");
		Map<String,Object> map= new HashMap<>();
		if(condition.getSmall_office_id()==null||condition.getSmall_office_id()==""){
			map.put("list", null);
			map.put("result","请选择科室");
		}else{
			List<Doctor_arrangeVo> list = hosp_patien.load_doctor_by_small_office(
					condition.getSmall_office_id(),condition.getDate(),condition.getClasses());
			map.put("list", list);
			map.put("result", "这个时间没有医生值班哦！");
		}
		mv.addObject("map",map);
		return mv;
	}
	
	/**
	 * 生成挂号账单
	 * @param doctor_title
	 * @return
	 */
	@RequestMapping("to_charge_guahao")
	public ModelAndView to_charge_guahao(String doctor_title_name){
		ModelAndView mv=new ModelAndView("charge_guahao");
		System.out.println(doctor_title_name+"===============");
		if(doctor_title_name==null||doctor_title_name==""){
		}else{
			mv.addAllObjects(hosp_patien.get_guahao_charge_message(doctor_title_name));
		}
		return mv;
	}
	
	/**
	 * 返回挂号号码，添加收费记录
	 * @param project_id
	 * @param project_name
	 * @param doctor_id
	 * @param doctor_title
	 * @param doctor_name
	 * @param cost
	 * @param crad_id
	 * @return
	 */
	@RequestMapping("pay_guahao")
	public ModelAndView pay_guahao(String project_id,String project_name,String doctor_id,String doctor_title,String doctor_name,Double cost,String crad_id){
		ModelAndView mv=new ModelAndView("charge_guahao");
		System.out.println();
		if(doctor_title==null||doctor_title==""){
		}else{
			mv.addAllObjects(hosp_patien.get_guahao_charge_message(doctor_id));
		}
		return mv;
	}
	
	/**
	 * 验证诊疗卡成功后挂号，返回结果
	 * @param card_id
	 * @param date
	 * @param classes
	 * @param doctor_id
	 * @param charge_id
	 * @return
	 * @throws ParseException
	 */
	@RequestMapping("verify_card_and_charge")
	@ResponseBody
	public String verify_card_and_charge(String card_id,String date,String classes,String doctor_id,Long project_id) throws ParseException{
		return hosp_patien.verify_card_and_charge(card_id, date, classes, doctor_id, project_id);
	}
	
	/**
	 * 跳到改号页面
	 * @return
	 */
	@RequestMapping("to_change_reg")
	public String to_change_reg(){
		return "change_reg";
	}
	
	/**
	 * 加载科室大类
	 * @return
	 */
	@RequestMapping("get_big_office")
	@ResponseBody
	public List<BigOffice> get_big_office(){
		return hosp_patien.get_big_office();
	}
	
	/**
	 * 根据科室大类加载科室小类
	 * @param big_office_id
	 * @return
	 */
	@RequestMapping("get_small_office")
	@ResponseBody
	public List<SmallOffice> get_small_office(int big_office_id){
		return hosp_patien.get_small_office(big_office_id);
	}
	
	/**
	 * 根据科室小类、日期、班次加载医生排班信息
	 * @param small_office_id
	 * @param data_
	 * @return
	 */
	@RequestMapping("get_doctor_arrange")
	@ResponseBody
	public List<Doctor_arrangeVo> get_doctor_arrange(Integer small_office_id,Date data_,String classes){
		System.out.println(data_);
		return hosp_patien.get_doctor_arrange(small_office_id, data_,classes);
	}
	
	/**
	 * 获取7天日期
	 */
	@RequestMapping("get_seven_date")
	@ResponseBody
	public List<Map<String,String>> get_seven_date(){
		String[] date= hosp_patien.get_seven_date();
		List<Map<String,String>> list=new ArrayList<>();
		for(int i=0,k=date.length;i<k;i++){
			Map<String,String> map=new HashMap<>();
			map.put("date", date[i]);
			map.put("id", date[i]);
			list.add(map);
		}
		return list;
	}
	/**
	 * 检查是否需要补钱或者退钱
	 * @param oldId
	 * @param newId
	 * @return
	 */
	@RequestMapping("checkRegMoney")
	@ResponseBody
	public String checkRegMoney(String oldId,String doctor_id){
		return hosp_patien.checkRegMoney(oldId, doctor_id);
	}
	
	/**
	 * 改号
	 * @param date_
	 * @param classes
	 * @param reg_id
	 * @param doctor_id
	 * @return
	 */
	@RequestMapping("changeReg")
	@ResponseBody
	public String changeReg(String date_,String classes,String reg_id,String doctor_id){
		return hosp_patien.changeReg(date_, classes, reg_id, doctor_id);
	}
}
